package com.tengju.bff.interfaces.covercharge.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.idanchuang.component.base.JsonResult;
import com.idanchuang.component.base.util.StringUtil;
import com.tengju.bff.interfaces.covercharge.entity.vo.AdminServiceCustomQueryVo;
import com.tengju.bff.interfaces.covercharge.service.IServiceCustomDetailService;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.ManageEntrance;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


/**
 * @author fwy
 */
@Api(value = "serviceCustom", tags = "客户收益余额明细")
@RestController
@Slf4j
@RequestMapping("/manage/bill/serviceCustom")
@ManageEntrance
public class AdminServiceCustomController {

    @Autowired
    IServiceCustomDetailService serviceCustomDetailService;

    @GetMapping
    @ApiOperation(value = "客户收益余额明细查询", notes = "客户收益余额明细查询")
    public ApiResponse<IPage<AdminServiceCustomQueryVo>> query(String codeId,
                                                              @RequestParam(defaultValue = "0", name = "pageNo") Integer pageNo,
                                                              @RequestParam(defaultValue = "10", name = "limit") Integer limit, String startDate, String endDate,
                                                              String orderId, String otherId, String des, String type) {
        //1.如果没有查询条件就设置成今天
        if(StringUtil.isBlank(startDate)&&StringUtil.isBlank(orderId)&&StringUtil.isBlank(otherId)&&StringUtil.isBlank(des)&&StringUtil.isBlank(type)&&StringUtil.isBlank(codeId)){
            startDate = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.now());
        }
        //2.存储关联表id集合
        des = StringUtils.deleteWhitespace(des);
        return ApiResponse.newSuccess(serviceCustomDetailService
                .queryPageByIdCode(new Page<>(pageNo, limit), codeId, orderId, otherId, des, type, startDate, endDate));
    }

}
